﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using TXK.CommonBase;
using MiniExcelLibs;
using MiniExcelLibs.Attributes;

namespace TXK
{
    public class VariableBase : INotifyPropertyChanged
    {
        public VariableBase()
        {

        }
        /// <summary>
        /// 变量名
        /// </summary>
        [ExcelColumnName("变量名")] public string VarName { get; set; } = Guid.NewGuid().ToString();
        /// <summary>
        /// 变量地址Md0/Qw1/I0.2 等等形式
        /// </summary>
        [ExcelColumnName("变量地址")]
        public string VarAddress { get; set; } = Guid.NewGuid().ToString();
        /// <summary>
        /// 变量的数据类型
        /// </summary>
        [ExcelColumnName("数据类型")] public DataType DataType { get; set; }
        /// <summary>
        /// 报警是否启用
        /// </summary>
        [ExcelColumnName("是否报警")] public bool AlarmEnable { get; set; } = false;
        /// <summary>
        /// 归档是否启用
        /// </summary>
        [ExcelColumnName("是否归档")] public bool ArchiveEnable { get; set; } = false;
        /// <summary>
        /// 报警类型，True为条件报警，False为离散(上升沿下降沿)报警
        /// 默认离散报警
        /// </summary>
        [ExcelColumnName("报警类型(条件或离散)")] public AlarmType AlarmType { get; set; } = AlarmType.条件报警;
        private object _value;
        /// <summary>
        /// 变量值
        /// </summary>
        [ExcelColumnName("当前值")]
        public object Value
        {
            get { return _value; }
            set
            {
                if (_value != value)
                {
                    _value = value;
                    OnPropertyChanged("Value");
                }
            }
        }
        #region 设定值
        /// <summary>
        /// 设定限值是否启用
        /// </summary>
        [ExcelColumnName("设定限值是否启用")] public bool SetLimitEnable { get; set; } = false;
        /// <summary>
        /// 设定值最大值
        /// </summary>
        [ExcelColumnName("设定值最大值")] public float SetLimitMax { get; set; } = 100f;
        /// <summary>
        /// 设定值最小值
        /// </summary>
        [ExcelColumnName("设定值最小值")] public float SetLimitMin { get; set; } = 0f;
        #endregion

        #region 离散报警
        /// <summary>
        /// 离散报警类型，True为上升沿报警，False为下降沿报警
        /// </summary>
        [ExcelColumnName("离散报警类型")] public DiscreteAlarmType DiscreteAlarmType { get; set; } = DiscreteAlarmType.上升沿报警;
        /// <summary>
        /// 离散报警上升沿缓存值
        /// </summary>
        [ExcelIgnore] public bool DiscreteRiseCacheValue { get; set; } = false;
        /// <summary>
        /// 离散报警下降沿缓存值
        /// </summary>
        [ExcelIgnore] public bool DiscreteFallCacheValue { get; set; } = true;
        /// <summary>
        /// 离散报警优先级
        /// </summary>
        [ExcelColumnName("离散报警优先级")] public int DiscreteAlarmPriority { get; set; } = 0;
        /// <summary>
        /// 离散报警说明
        /// </summary>
        [ExcelColumnName("离散报警说明")] public string DiscreteAlarmNote { get; set; } = string.Empty;
        #endregion

        #region 低报警
        /// <summary>
        /// 低报警是否启用
        /// </summary>
        [ExcelColumnName("低报警是否启用")] public bool LowAlarmEnable { get; set; } = false;
        /// <summary>
        /// 低报警设定值
        /// </summary>
        [ExcelColumnName("低报警设定值")] public float LowAlarmValue { get; set; } = 0f;
        /// <summary>
        /// 低报警缓存值
        /// </summary>
        [ExcelIgnore()] public float LowCacheValue { get; set; } = float.MaxValue;
        /// <summary>
        /// 低报警优先级
        /// </summary>
        [ExcelColumnName("低报警优先级")] public int LowAlarmPriority { get; set; } = 0;
        /// <summary>
        /// 低报警说明
        /// </summary>
        [ExcelColumnName("低报警说明")] public string LowAlarmNote { get; set; } = string.Empty;
        #endregion

        #region 超低报警
        /// <summary>
        /// 低低报警是否启用
        /// </summary>
        [ExcelColumnName("低低报警是否启用")] public bool LoLoAlarmEnable { get; set; } = false;
        /// <summary>
        /// 低低报警设定值
        /// </summary>
        [ExcelColumnName("低低报警设定值")] public float LoLoAlarmValue { get; set; } = 0f;
        /// <summary>
        /// 低低报警缓存值
        /// </summary>
        [ExcelIgnore()] public float LoLoCacheValue { get; set; } = float.MaxValue;
        /// <summary>
        /// 低低报警优先级
        /// </summary>
        [ExcelColumnName("低低报警优先级")] public int LoLoAlarmPriority { get; set; } = 0;
        /// <summary>
        /// 低低报警说明
        /// </summary>
        [ExcelColumnName("低低报警说明")] public string LoLoAlarmNote { get; set; } = string.Empty;
        #endregion

        #region 高报警
        /// <summary>
        /// 高报警是否启用
        /// </summary>
        [ExcelColumnName("高报警是否启用")] public bool HighAlarmEnable { get; set; } = false;
        /// <summary>
        /// 高报警设定值
        /// </summary>
        [ExcelColumnName("高报警设定值")] public float HighAlarmValue { get; set; } = 0f;
        /// <summary>
        /// 高报警缓存值
        /// </summary>
        [ExcelIgnore()] public float HighCacheValue { get; set; } = float.MinValue;
        /// <summary>
        /// 高报警优先级
        /// </summary>
        [ExcelColumnName("高报警优先级")] public int HighAlarmPriority { get; set; } = 0;
        /// <summary>
        /// 高报警说明
        /// </summary>
        [ExcelColumnName("高报警说明")] public string HighAlarmNote { get; set; } = "高报警";
        #endregion

        #region 超高报警
        /// <summary>
        /// 高高报警是否启用
        /// </summary>
        [ExcelColumnName("高高报警是否启用")] public bool HiHiAlarmEnable { get; set; } = false;
        /// <summary>
        /// 高高报警设定值
        /// </summary>
        [ExcelColumnName("高高报警设定值")] public float HiHiAlarmValue { get; set; } = 0f;
        /// <summary>
        /// 高高报警缓存值
        /// </summary>
        [ExcelIgnore()] public float HiHiCacheValue { get; set; } = float.MinValue;
        /// <summary>
        /// 高高报警优先级
        /// </summary>
        [ExcelColumnName("高高报警优先级")] public int HiHiAlarmPriority { get; set; } = 0;
        /// <summary>
        /// 高高报警说明
        /// </summary>
        [ExcelColumnName("高高报警说明")] public string HiHiAlarmNote { get; set; } = string.Empty;
        #endregion

        /// <summary>
        /// 归档时间
        /// </summary>
        [ExcelColumnName("归档时间")] public int ArchivePeriod { get; set; }

        #region 依赖属性
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string properName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(properName));
            }
        }
        #endregion



    }
}

